package com.google.code.sip.ucenter.converter;

import java.util.Date;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.apache.commons.beanutils.converters.DoubleConverter;
import org.apache.commons.beanutils.converters.FloatConverter;
import org.apache.commons.beanutils.converters.IntegerConverter;
import org.apache.commons.beanutils.converters.LongConverter;
import org.apache.commons.beanutils.converters.StringConverter;

import com.google.code.sip.core.converter.EnumConverter;
import com.google.code.sip.ucenter.model.CreditOperation;
import com.google.code.sip.ucenter.model.CreditRuleCycleType;
import com.google.code.sip.ucenter.model.Gender;
import com.google.code.sip.ucenter.model.IdCardType;
import com.google.code.sip.ucenter.model.PrivacyType;

public class ConverterUtils {

	/**
	 * 注册转换转换
	 */
	public static void registConverter() {
		ConvertUtils.register(new StringConverter(), String.class);
		ConvertUtils.register(new IntegerConverter(null), Integer.class);
		ConvertUtils.register(new LongConverter(null), Long.class);
		ConvertUtils.register(new FloatConverter(null), Float.class);
		ConvertUtils.register(new DoubleConverter(null), Double.class);
		ConvertUtils.register(new EnumConverter(), Gender.class);
		ConvertUtils.register(new EnumConverter(), IdCardType.class);
		ConvertUtils.register(new EnumConverter(), CreditOperation.class);
		ConvertUtils.register(new EnumConverter(), CreditRuleCycleType.class);
		ConvertUtils.register(new EnumConverter(), PrivacyType.class);
		DateConverter dc = new DateConverter();
		dc.setUseLocaleFormat(true);
		dc.setPatterns(new String[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss" });
		ConvertUtils.register(dc, Date.class);
	}
}
